//
//  JYTMeHeadView.m
//  JYT_IOS
//
//  Created by nxa-tankeke on 16/12/29.
//  Copyright © 2016年 nxa-yuanguoxiang. All rights reserved.
//

#import "JYTMeHeadView.h"
#import <UIImageView+WebCache.h>

@interface JYTMeHeadView()
@property (nonatomic, strong) UIImageView *imagV;
@property (nonatomic, strong) UIView *info;

@property (nonatomic, strong) UIButton *loginBtn;
@property (nonatomic, weak) UIView *learnTV;
@property (nonatomic, strong) UILabel *nameL;
@property (nonatomic, strong) UILabel *nickL;


@end

@implementation JYTMeHeadView

- (id)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setBackgroundColor:[UIColor whiteColor]];
        
        UIView *top = [[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, 130)];
        top.backgroundColor = [UIColor colorWithRed:131/255.0f green:182/255.0f blue:248/255.0f alpha:1];
        [self addSubview:top];
        
        _imagV = [[UIImageView alloc]initWithFrame:CGRectMake((top.frame.size.width - 60) * 0.5, 0, 60, 60)];
        self.imagV.layer.cornerRadius = self.imagV.bounds.size.width / 2;
        self.imagV.clipsToBounds = YES;
        [self.imagV setImage:[UIImage imageNamed:@"tx_w"]];
        [top addSubview:_imagV];
        
   
        _info = [[UIView alloc]initWithFrame:CGRectMake((top.frame.size.width - CURRENT_SCREEN_WIDTH/2) * 0.5, 60, 170, 70)];
        _info.backgroundColor = [UIColor clearColor];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(dosomething)];
        [_info addGestureRecognizer: tap];
        [top addSubview:_info];
        
        _nameL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CURRENT_SCREEN_WIDTH/2, 35)];
        //[_nameL setText:@"用户名:17704333142"];
        _nameL.textAlignment = NSTextAlignmentLeft;
//        _nameL.textAlignment = UITextAlignmentCenter;
        [_info addSubview:_nameL];
        
        _nickL = [[UILabel alloc]initWithFrame:CGRectMake(0, 35, CURRENT_SCREEN_WIDTH/2, 35)];
        //[_nickL setText:@"昵称 : 抱抱"];
        _nickL.textAlignment = NSTextAlignmentLeft;
        [_info addSubview:_nickL];
        _info.hidden = YES;
        
        
        _loginBtn = [[UIButton alloc]initWithFrame:CGRectMake((top.frame.size.width - 130) * 0.5, 60, 130, 70)];
        [_loginBtn setTintColor:[UIColor blackColor]];
        [_loginBtn setTitle:@"注册/登陆" forState:UIControlStateNormal];
        [_loginBtn.titleLabel setFont:[UIFont systemFontOfSize:17.0]];
        [_loginBtn addTarget:self action:@selector(clickloginBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_loginBtn];
        
    }
    return self;
}


- (void)dosomething
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickInfoView)]) {
        
        [self.delegate clickInfoView];
    }
}

- (void)clickloginBtn
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(loginClicked)]) {
        
        [self.delegate loginClicked];
    }
}

- (void)loginWithUserName:(NSString *)userName nick:(NSString *)nickName  headerUrl:(NSString *)url learnTime:(NSDictionary *)dict
{
    self.info.hidden = NO;
    self.loginBtn.hidden = YES;
    [self.nameL setText:[NSString stringWithFormat:@"用户名:%@", userName]];
    if (nickName.length>0) {
        [self.nickL setText:[NSString stringWithFormat:@"昵 称: %@", nickName]];
    }else{
        [self.nickL setText:[NSString stringWithFormat:@"昵 称: %@", @"无"]];
    }
    if (url.length == 0) {
        [self.imagV setImage:[UIImage imageNamed:@"tx_w"]];
    } else {
        [self.imagV sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"tx_w"]];

    }
}


@end
